<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>物流承担方</title>
    <link rel="stylesheet" type="text/css" href="../../../../start/layui/css/layui.css"/>
    <script src="../../../../start/layui/layui.js"></script>
    <style>
        .layui-form-select .layui-input {
            padding-right: 0px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-row" style="padding-top: 10px;">
        <div class="layui-col-md4">
            <div class="layui-inline">
                <label class="layui-form-label">承担单位</label>
                <div class="layui-input-inline">
                    <input type="tel" name="forwardingunit" id="forwardingunit" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-inline">
                <label class="layui-form-label">电话号码</label>
                <div class="layui-input-inline">
                    <input type="tel" name="phone" id="phone" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-inline">
                <label class="layui-form-label">备用电话</label>
                <div class="layui-input-inline">
                    <input type="tel" name="alternatephone" id="alternatephone" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row" style="padding-top: 10px;">
        <div class="layui-col-md8">
            <div class="layui-form-item"  style="margin-bottom: 5px">
                <label class="layui-form-label">请选择</label>
                <div class="layui-inline">
                    <select name="province" id="province" class="province"  lay-search lay-filter="province">
                        <option value="">省份</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="city" id="city"     class="city"  lay-search lay-filter="city">
                        <option value="">地级市</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="district" id="district"   lay-filter="district1"  class="district"  lay-search >
                        <option value="">县/区</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-inline">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-inline">
                    <input type="tel" name="remark" id="detailedAddress" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-md4">
            <div class="layui-inline">
                <label class="layui-form-label">联系人姓名</label>
                <div class="layui-input-inline">
                    <input type="tel" name="name" id="name" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-col-md4">
            <div class="layui-inline">
                <label class="layui-form-label">银行卡号</label>
                <div class="layui-input-inline">
                    <input type="tel" name="bankcard" id="bankcard" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-inline">
                <label class="layui-form-label">&nbsp;</label>
                <div class="layui-input-inline">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                </div>
            </div>

        </div>
    </div>
</form>
</body>
</html>
<!-- 三级联动 -->
<script type="text/javascript" src="../../../../start/layui/js/area2.js"></script>
<script type="text/javascript" src="../../../../start/layui/js/xcl.js"></script>
<script>
    layui.use(['form','jquery'], function() {
        var form = layui.form;
        var $ = layui.jquery;
        //显示网址
        var locationi=location.href;
        //根据下标截取字符串获得id
        var id=locationi.substring(locationi.indexOf("=")+1);
        //根据id数据回滚
        if (id!=0){
            $.ajax({
                url: "../../../../getLogisticsById",
                type: "post",
                data: {
                    id:id
                },
                dataType: "json",
                success: function (data) {
                    //承担单位
                    $("#forwardingunit").val(data.forwardingunit)
                    //电话号码
                    $("#phone").val(data.phone)
                    //银行卡号
                    $("#bankcard").val(data.bankcard)
                    //备用电话
                    $("#alternatephone").val(data.alternatephone)
                    //地址
                    $("#detailedAddress").val(data.remark)
                    //姓名
                    $("#name").val(data.name)
                }
            })
        }

        //提交
        form.on('submit(demo1)', function(data){
            //判断是新增还是修改
            if (id!=0){
                $.ajax({
                    url: "../../../../updateLogistics",
                    type: "get",
                    data: {
                        logisticsId:id,
                        forwardingunit:$("#forwardingunit").val(),
                        phone:$("#phone").val(),
                        bankcard:$("#bankcard").val(),
                        tms_region:$("#detailedAddress").val(),
                        name:$("#name").val(),
                        alternatephone:$("#alternatephone").val()
                    },
                    dataType: "text",
                    success: function (data) {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        layer.closeAll("iframe");//关闭iframe层
                        //修改成功后刷新父界面
                        window.parent.location.reload();
                    }
                })
            }else {
                $.ajax({
                    url: "../../../../insertLogistics",
                    type: "post",
                    data: {
                        forwardingunit:$("#forwardingunit").val(),
                        phone:$("#phone").val(),
                        bankcard:$("#bankcard").val(),
                        tms_region:$("#detailedAddress").val(),
                        name:$("#name").val(),
                        alternatephone:$("#alternatephone").val(),
                    },
                    dataType: "text",
                    success: function (data) {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        layer.closeAll("iframe");//关闭iframe层
                        //修改成功后刷新父界面
                        window.parent.location.reload();
                    }
                })
            }
            return false;
        });
    })
</script>
